//导入 验证插件
import Vue from "vue";
import zh_CN from 'vee-validate/dist/locale/zh_CN';
import VeeValidate, { Validator } from 'vee-validate';
Vue.use(VeeValidate);
Validator.localize('zh_CN', zh_CN);

import { phoneReg, codeReg, pwdReg } from "@/utils/reg"


//创建自定义验证规则  手机号
Validator.extend('phone', {
    validate: value => {
        return phoneReg.test(value);
    },
    getMessage: field => "手机号码格式错误！"
});


// 重写数据为空的规则
Validator.extend('required', {
    validate: value => {
        return value;
    },
    getMessage: field => field + "不能为空！"
});



//验证码的验证规则
Validator.extend('code', {
    validate: value => codeReg.test(value),//验证规则
    getMessage: filed => '验证码必须为6位数字！', //验证失败的回调
});

//密码的验证规则
Validator.extend('pwd', {
    validate: value => pwdReg.test(value),//验证规则
    getMessage: filed => '密码为6到21位英文、数字、下划线', //验证失败的回调
});

//重复密码的验证规则
Validator.extend('ispwd', {
    validate: (value, args) => value === args[0],//验证规则
    getMessage: filed => '重复密码必须和登录密码一致', //验证失败的回调
});

//协议规则
Validator.extend('isagree', {
    validate: value => value,//验证规则
    getMessage: filed => '协议必须同意！', //验证失败的回调
});